$(function(){
	
	
	
	//获取总页数
	$.getJSON('../../AllPages',{
		flag:'pet'
	},function(data,status){
		if(status){
			console.log(data[0].pages);
			var pages = data[0].pages;
			
			$('#pageLimit').bootstrapPaginator({
				currentPage : 1,
				totalPages : parseInt(pages),
				size : "normal",
				bootstrapMajorVersion : 3,
				alignment : "right",
				numberOfPages : 5,
				itemTexts : function(type, page, current) {
					switch (type) {
					case "first":
						return "首页";
					case "prev":
						return "上一页";
					case "next":
						return "下一页";
					case "last":
						return "末页";
					case "page":
						return page;
					}
				},

				onPageClicked : function(event, originalEvent, type, page) {
					console.log("1:" + page);
					
					allPetPage(page);
					
//					console.log(page);
				},
			});
			
			
			
		}
	});
	
	
	
	
	
	
	function allPetPage(page){
		$.getJSON('../../PetInfoPage',{
			pageShowNumber:5,
			currentPage:page
		},function(data,status){
			
			$('tbody').empty();
			for(var i=0;i<data.length;i++){
				var state='';
				if(data[i].ANIMAL_STATE=='1'||data[i].STATE==1){
					state = '上架';
				}else{
					state = '未上架';
				}
//				console.log(data[i].ID+data[i].ANIMAL_NAME+data[i].ANIMAL_SEX);
				$('tbody').append('<tr><td>'+data[i].ID+'</td><td>'+data[i].ANIMAL_NAME+'</td><td>'+data[i].ANIMAL_NICKNAME
						+'</td><td class="center">'+data[i].ANIMAL_SEX+'</td><td class="center">'+data[i].ANIMAL_COLOR+'</td><td class="center">'+state+'</td>'
						+'<td class="center"><div class="btn-group">'
						+'<button type="button" class="btn btn-default"id="petInfoBtn" onclick="updatePetInfo(this)" data-pet-id="'+data[i].ID+'">详细信息</button>'
						+'<button type="button" class="btn btn-default"id="petUpdateBtn" onclick="updatePetInfo(this)" data-pet-id="'+data[i].ID+'">修改</button>'
						+'<button type="button" class="btn btn-default"id="delPetBtn" onclick="delPet(this)" data-pet-id="'+data[i].ID+'">删除</button></div></td></tr>');
				
			}
			
		});
	}
	
//	<tr><td>Trident</td><td>Internet Explorer 4.0</td><td>Win 95+</td><td class="center">4</td><td class="center">4</td><td class="center">4</td><td class="center"><div class="btn-group" data-pet-id="1"><button type="button" class="btn btn-default"id="petInfoBtn">详细信息</button><button type="button" class="btn btn-default"id="petUpdateBtn">修改</button><button type="button" class="btn btn-default"id="delPetBtn">删除</button></div></td></tr>	
	
	//显示第一页
	allPetPage(1);
	
	
	
	
	function showCategorys(flag,big){
		// 1,big   2,small
		$.getJSON('../../ShowCg.do',{
			flag:flag,
			bigcategory:big
		},function(data,status){
			if(status){
				if(flag == '1' || flag == 1){
					$('.up-big-category').empty();
					for(var i = 0; i< data.length ;i++){
						$('.up-big-category').append('<option>'+data[i].NAME+'</option>');
					}
				}else{
					$('.up-small-category').empty();
					for(var i = 0; i< data.length ;i++){
						$('.up-small-category').append('<option>'+data[i].NAME+'</option>');
					}
				}
			}
		});
	}
	
	
	showCategorys(1,0);
	showCategorys(2,'狗');
	
	$('.up-big-category').change(function(){
		
		var sm = $('.up-big-category').val();
		
		showCategorys(2,sm);
		
	});
	
})

function asdf(){
		alert("456");
	}